﻿app.controller("homeController", function ($scope, $http, $routeParams, $window, LoginService, $location, Cart) {
    $scope.cart = Cart;
    $scope.getGadgets = function () {
        $http({ method: "GET", url: "api/ApiGadget" })
        .success(function (data) {
            $scope.Gadgets = data;
        })
    };
    $scope.newGadget = function () {
        console.log("new gadget firing");
        $http({ method: "POST", url: "api/ApiGadget", data: $scope.Gadget })
        .success(function (id) {
            $location.path("/admin_product_details/" + id);
        })
    };
    $scope.deleteGadget = function (id) {
        $http({ method: "DELETE", url: "api/ApiGadget/" + id, data: $scope.Gadget })
        .success(function (data) {
            $scope.getGadgets();
        })
    }
    $scope.addItem = function (id) {
        $http({ method: "GET", url: "api/ApiGadget/" + id })
            .success(function (gadgetVM) {
                Cart.push(gadgetVM.Gadget);
                //$scope.$apply();
                console.log($scope.cart);
            })
    };
    $scope.getPagedGadgets = function (pageNum) {
        $http({ method: "GET", url: "api/ApiAllView/" + pageNum})
            .success(function (gadgets) {
                $scope.Gadgets = gadgets;
            });
    }

    //$scope.getPagedGadgets(1);
    $scope.getGadgets();
})